<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
use \think\Config;


function show($code, $message ='', $data = []){

    if($code == 200) {
        $message = "数据返回成功";
    } else if ($code == 400) {
        $message = "未获取到参数";
    } else if ($code == 401) {
        $message = "账号或密码错误！";
    }else if ($code == 402) {
        $message = "手机号码已经注册,请更换";
    }else if ($code == 403) {
        $message = "返回数据失败";
    }else if ($code == 405) {
        $message = "验证码错误";
    }else if ($code == 406) {
        $message = "验证码过期";
    }else if ($code == 407) {
        $message = "数据没有更新";
    }else if ($code == 408) {
        $message = "原始密码错误";
    }else if ($code == 409) {
        $message = "参数不完整";
    }else if ($code == 410) {
        $message = "token过期,请重新登录";
    }else if ($code == 411) {
        $message = "手机号码未注册";
    }else if ($code == 412) {
        $message = "用户身份错误";
    }else if ($code == 413) {
        $message = "店铺审核通过请勿重复审核";
    }else if ($code == 415) {
        $message = "用户信息未填写";
    }else if ($code == 416) {
        $message = "还未创建活动";
    }else if ($code == 417) {
        $message = "该活动已经存在";
    }else if ($code == 418) {
        $message = "该活动不存在或者已经下架";
    }else if ($code == 419) {
        $message = "离你预约的时间还有1个小时，咱不能取消预约哦";
    }else if ($code == 420) {
        $message = "预约取消";
    }else if ($code == 421) {
        $message = "密码不正确";
    }else if ($code == 422) {
        $message = "密码和原始密码不一致";
    }else if ($code == 423) {
        $message = "暂无没有符合条件的医生";
    }else if ($code == 424) {
        $message = "您还有预约未完成";
    }else if ($code == 425) {
        $message = "此时间段预约失效";
    }else if ($code == 426) {
        $message = "邮箱地址不存在";
    }else if ($code == 1) {
        $message = "经济人员";
    }else if ($code == 2) {
        $message = "设计人员";
    }else if ($code == 3) {
        $message = "管理人员";
    }else if ($code == 427) {
        $message = "返回数据为空";
    }else if ($code == 428) {
        $message = "您没有权限删除，请联系网站管理者";
    }else if ($code == 429) {
        $message = "输入的密码与原始密码一样";
    }else if ($code == 430) {
        $message = "不能再次添加超级管理";
    }else if ($code == 431) {
        $message = "用户名已存在，请重新输入";
    }else if ($code == 432) {
        $message = "不能删除自己";
    }else if ($code == 433) {
        $message = "不能删除超级管理员";
    }else if ($code == 434) {
        $message = "没有权限操作超级管理员";
    }else if ($code == 435) {
        $message = "不能停用自己";
    }else if ($code == 436) {
        $message = "不是商家用户";
    }else if ($code == 437) {
        $message = "商家账号未审核";
    }else if ($code == 438) {
        $message = "账号不存在";
    }else if ($code == 439) {
        $message = "没有收获地址";
    }

    if($data == []) {
        $data = array('code' => $code, 'msg' => $message);
        return  json($data);

    } else {
        $data = array('code' => $code, 'msg' => $message, 'data' => $data);
        return  json($data);
    }
}


function isMobile()
{
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
    {
        return true;
    }
    if (isset ($_SERVER['HTTP_VIA']))
    {
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    }
    if (isset ($_SERVER['HTTP_USER_AGENT']))
    {
        $clientkeywords = array ('nokia',
            'sony',
            'ericsson',
            'mot',
            'samsung',
            'htc',
            'sgh',
            'lg',
            'sharp',
            'sie-',
            'philips',
            'panasonic',
            'alcatel',
            'lenovo',
            'iphone',
            'ipod',
            'blackberry',
            'meizu',
            'android',
            'netfront',
            'symbian',
            'ucweb',
            'windowsce',
            'palm',
            'operamini',
            'operamobi',
            'openwave',
            'nexusone',
            'cldc',
            'midp',
            'wap',
            'mobile'
        );
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
        {
            return true;
        }
    }
    if (isset ($_SERVER['HTTP_ACCEPT']))
    {
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
        {
            return true;
        }
    }
    return false;
}

